<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="600px" top="0" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="80px" v-loading="loading">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="部门类型" prop="type">
						<el-radio-group v-model="formData.type" v-removeAriaHidden:radio>
							<el-radio label="1">学院(校区)</el-radio>
							<el-radio label="2">系(部)</el-radio>
							<el-radio label="3">教研室</el-radio>
							<el-radio label="4">其他</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="部门名称" prop="name">
						<el-input v-model="formData.name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="上级部门" prop="pid">
						<sw-depart-select v-model="formData.pid" istop :disabled="child" placeholder="请选择上级部门" style="width: 100%" />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="部门编码" prop="code">
						<sw-custom-input type="capital" v-model="formData.code" placeholder="请输入部门编码" />
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="负责人" prop="manager">
						<sw-user-select v-model="formData.manager"></sw-user-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="排序" prop="sort">
						<el-input-number v-model="formData.sort" controls-position="right" :min="1" style="width: 100%"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="部门描述">
						<el-input type="textarea" v-model="formData.content"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm()">{{ formTypeName }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import lodash from 'lodash';
import formMixins from '@/mixins/formMixins';
import { queryDepart, addedDepart, updateDepart } from '@/api/system/tbSysDept';
export default {
	mixins: [formMixins],
	props: {
		list: { type: Array, default: () => [] }
	},
	data() {
		return {
			formName: '部门',
			formRules: {
				type: [{ required: true, message: '请选择部门类型', trigger: 'change' }],
				name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }],
				pid: [{ required: true, message: '请选择上级部门', trigger: 'change' }],
				code: [{ required: true, message: '请输入部门编码', trigger: 'blur' }]
			}
		};
	},
	computed: {
		detailData() {
			return eval(queryDepart);
		},
		callFunction() {
			return eval(!this.addOrEdit && !this.child ? updateDepart : addedDepart);
		},
		submitParams() {
			let params = { ...this.formData };
			if (this.child) delete params.id;
			return params;
		}
	},
	methods: {
		updateStoreData() {
			this.$store.dispatch('getDepartList');
		}
	}
};
</script>
